package com.easyboot.web.system.controller;

import com.easyboot.framework.domain.DataTableDto;
import com.easyboot.framework.domain.ResultAdaptDto;
import com.easyboot.framework.core.ActionResult;
import com.easyboot.framework.core.BaseController;
import com.easyboot.framework.core.RequestHelper;
import com.easyboot.web.system.domain.ExamRecord;
import com.easyboot.web.system.service.ExamRecordService;
import com.easyboot.web.system.service.SysPositionService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author yushuo
 * @className
 * @descripton TODO
 * @date 2021/3/1 12:26
 **/
@RequestMapping("/admin/exam")
@Controller
public class ExamController extends BaseController {
    @Autowired
    private RequestHelper requestHelper;
    @Autowired
    private SysPositionService postionService;
    @Autowired
    private ExamRecordService examRecordService;
    /**
     *
     * @author yushuo
     * @description 列表页
     * @date 14:32 2021/2/25
     * @param []
     * @return com.easyboot.framework.web.ActionResult
     **/
    @RequiresPermissions("system:exam:view")
    @GetMapping("/index")
    public ActionResult Index(){
        return view();
    }

    /**
     *
     * @author yushuo
     * @description 获取职位信息列表
     * @date 14:52 2021/2/25
     * @param [dto]
     * @return com.easyboot.framework.web.ActionResult
     **/
    @RequiresPermissions("system:exam:view")
    @PostMapping("/getList")
    public ActionResult getList(DataTableDto dto){
        String examName=requestHelper.getString("examName","");
        String postCode=requestHelper.getString("examCode","");

        dto=examRecordService.getList(dto,examName,postCode);
        return json(dto);
    }

    @RequiresPermissions(value = {"system:exam:add","system:exam:edit"},logical = Logical.OR)
    @GetMapping("/form")
    public ActionResult form(String id, Model model){

        model.addAttribute("id",id);
        return view();
    }

    /**
     *
     * @author yushuo
     * @description 获取职位信息
     * @date 14:51 2021/2/25
     * @param []
     * @return com.easyboot.framework.web.ActionResult
     **/
    @RequiresPermissions(value = {"system:exam:add","system:exam:edit"},logical = Logical.OR)
    @GetMapping("/getModel")
    public ActionResult getModel(){
        int id=requestHelper.getInt("id",0);
        if(id==0){
            return error("数据加载失败");
        }

        ExamRecord examRecord= examRecordService.getModel(id);
        ResultAdaptDto ret=new ResultAdaptDto();
        ret.put("model",examRecord);
        return json(ret);
    }
    /**
     *
     * @author yushuo
     * @description 保存数据
     * @date 14:55 2021/2/25
     * @param [dto]
     * @return com.easyboot.framework.web.ActionResult
     **/
    @RequiresPermissions(value = {"system:exam:add","system:exam:edit"},logical = Logical.OR)
    @PostMapping("/save")
    public ActionResult save(ExamRecord dto){

        examRecordService.saveModel(dto);

        return ok("职位信息保存成功");
    }
}
